﻿

using System;
using System.Diagnostics;
using System.Linq;
using DataModel.DataModelContext;

namespace DataModel.DataCenter
{
    public class GetLesson
    {
        private const string ConnectionString = @"isostore:/EnglishStudy.sdf";
        /// <summary>
        /// Delete Lesson
        /// </summary>
        /// <param name="stt"></param>
        public void DeleteLession(int stt)
        {
            try
            {

                using (var context = new EnglishStudyContext(ConnectionString))
                {
                    var query = (from d in context.TblLessons
                                 where d.Stt == stt
                                 select d);
                    if (query.Any())
                    {
                        context.TblLessons.DeleteAllOnSubmit(query);
                        context.SubmitChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + " offline home");
            }
        }
        /// <summary>
        /// Add Lesson to Database
        /// </summary>
        /// <param name="tblLesson"></param>
        public void AddTblLesson(TblLesson tblLesson)
        {
            try
            {
                using (var context = new EnglishStudyContext(ConnectionString))
                {
                    // create a new country and add it to the context
                    var lesson = new TblLesson();
                    lesson.Image = tblLesson.Image;
                    lesson.Title = tblLesson.Title;
                    lesson.ListContent = tblLesson.ListContent;
                    lesson.KindOfLesson = tblLesson.KindOfLesson;
                    lesson.PerCentDone = tblLesson.PerCentDone;

                    // save changes to the database
                    context.TblLessons.InsertOnSubmit(lesson);
                    context.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + " offline home");
            }
        }


    }
}
